﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
using AndrewSiemer.KnowledgeExchange.Core;
using AndrewSiemer.KnowledgeExchange.Core.Structure;
using AndrewSiemer.KnowledgeExchange.Domain;
using AndrewSiemer.KnowledgeExchange.Web.Controllers;
using NUnit.Framework;
using KnowledgeExchangeWeb;
using Rhino.Mocks;
using StructureMap;

namespace AndrewSiemer.KnowledgeExchange.Web.Tests.Controllers
{
    [TestFixture]
    public class HomeControllerTest
    {
        [Test]
        public void Index()
        {
            MockRepository mocks = new MockRepository();

            List<Post> testData = new List<Post>();
            for (int i = 0; i < 10; i++)
            {
                testData.Add(new Post(){Body = "Post Body", CreateDate = DateTime.Now, LastUpdated = DateTime.Now, PostID = i, ProfileID = 1, Title = "Post Title"});
            }

            IPostService postService = mocks.StrictMock<IPostService>();
            Expect.Call(postService.GetAllPosts()).Return(testData);

            mocks.ReplayAll();

            //// Arrange
            HomeController controller = new HomeController(postService);

            //// Act
            ViewResult result = controller.Index() as ViewResult;

            //// Assert
            ViewDataDictionary viewData = result.ViewData;

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(viewData["posts"] as List<Post>);
        }
    }
}